package fun.boomcat.luckyhe.mirai.plugin.dougu.service;

import fun.boomcat.luckyhe.mirai.plugin.dougu.mapper.DouguListMapper;
import fun.boomcat.luckyhe.mirai.plugin.dougu.pojo.Dougu;
import fun.boomcat.luckyhe.mirai.plugin.dougu.utils.MyBatisUtil;
import org.apache.ibatis.session.SqlSession;

import java.io.IOException;

public class DouguListServiceImpl implements DouguListService{
    @Override
    public int createDouguDB() throws IOException {
        SqlSession sqlSession = MyBatisUtil.getSqlSession();
        DouguListMapper mapper = sqlSession.getMapper(DouguListMapper.class);
        int res = mapper.createDouguDB();
        sqlSession.commit();
        sqlSession.close();

        return res;
    }

    @Override
    public int createDouguListTable() throws IOException {
        SqlSession sqlSession = MyBatisUtil.getSqlSession();
        DouguListMapper mapper = sqlSession.getMapper(DouguListMapper.class);
        int res = mapper.createDouguListTable();
        sqlSession.commit();
        sqlSession.close();

        return res;
    }

    @Override
    public int insertOneDougu(Dougu dougu) throws IOException {
        SqlSession sqlSession = MyBatisUtil.getSqlSession();
        DouguListMapper mapper = sqlSession.getMapper(DouguListMapper.class);
        int res = mapper.insertOneDougu(dougu);
        sqlSession.commit();
        sqlSession.close();

        return res;
    }
}
